package com.ryqg.jiaofu.web.controller;

import com.ryqg.jiaofu.business.common.PageResult;
import com.ryqg.jiaofu.common.Result;
import com.ryqg.jiaofu.domain.pagequery.pdfinfo.PDFInfoPageQuery;
import com.ryqg.jiaofu.domain.vo.OperationVO;
import com.ryqg.jiaofu.domain.vo.PDFInfoVO;
import com.ryqg.jiaofu.domain.vo.PopularPdfVO;
import com.ryqg.jiaofu.web.service.PDFService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/api/v1/pdf")
@AllArgsConstructor
public class PDFController {

    private final PDFService pdfService;

    @GetMapping("/view/{docId}")
    @ResponseBody
    public Result<String> pdfContent(@PathVariable String docId) {
        String html = pdfService.getPDFView(docId);
        return Result.success(html);
    }
    /**
     *用于首页最新文档接口，展示最新的10条数据
     * */
    @ResponseBody
    @GetMapping("/list")
    public Result<List<PDFInfoVO>> pdfList() {
        List<PDFInfoVO> pdfViewVOList = pdfService.getPDFList();
        return Result.success(pdfViewVOList);
    }
    /**
     *用于首页热门文档，展示下载量最多的10条数据
     * */
    @ResponseBody
    @GetMapping("/popular/list")
    public Result<List<PopularPdfVO>> popularPdfList() {
        List<PopularPdfVO> pdfViewVOList = pdfService.popularPdfList();
        return Result.success(pdfViewVOList);
    }
    /**
     *用于首页用户动态，展示最近10条的数据
     * */
    @ResponseBody
    @GetMapping("/user/activity")
    public Result<List<OperationVO>> userActivity() {
        List<OperationVO> operationVOList = pdfService.userActivity();
        return Result.success(operationVOList);
    }

    @ResponseBody
    @GetMapping("/doc_list")
    public Result<PageResult<PDFInfoVO>> searchPDFList(PDFInfoPageQuery pdfInfoPageQuery) {
        PageResult<PDFInfoVO> pdfViewVOList = pdfService.searchPDFList(pdfInfoPageQuery);
        return Result.success(pdfViewVOList);
    }
}